[flake8-simplify] add fix safety section (SIM110)#18114
[flake8-simplify] add fix safety section (SIM110)#18114ntBre merged 2 commits intoastral-sh:mainfrom
flake8-simplify] add fix safety section (SIM110)#18114Conversation
|
|
That's quite an exotic example! I'm not sure if it's doing exactly what you think, though. I tried switching the order in which I call Original order>>> def predicate(item):
... global called
... called += 1
... if called == 1:
... # after first call we change the method
... def new_predicate(_): return False
... globals()['predicate'] = new_predicate
... return True
...
... def foo():
... for item in range(10):
... if predicate(item):
... return True
... return False
...
... def foo_gen():
... return any(predicate(item) for item in range(10))
...
... called = 0
... print(foo()) # true – returns immediately on first call
...
... called = 0
... print(foo_gen()) # false – second call uses new `predicate`
...
True
FalseSwapped order>>> def predicate(item):
... global called
... called += 1
... if called == 1:
... # after first call we change the method
... def new_predicate(_): return False
... globals()['predicate'] = new_predicate
... return True
...
... def foo():
... for item in range(10):
... if predicate(item):
... return True
... return False
...
... def foo_gen():
... return any(predicate(item) for item in range(10))
...
... called = 0
... print(foo_gen()) # true – returns immediately on first call
...
... called = 0
... print(foo()) # false – second call uses new `predicate`
...
True
FalseI think both versions use the same So removing comments might be the main reason for unsafety here. |
|
@ntBre You are right. :-) I just added the fact it could remove comment. Other question: we could make the fix safe when it doesn't remove comments right? |
ntBre
left a comment
There was a problem hiding this comment.
Thanks!
Other question: we could make the fix safe when it doesn't remove comments right?
Yes, I think that's right since we couldn't come up with any other reason for the unsafety.
The PR add the
fix safetysection for ruleSIM110(#15584 )Unsafe Fix Example
Note
I notice that here we have two rules,
SIM110&SIM111. The second one seems not anymore active. Should I deleteSIM111?